using System.Threading;
using System.Windows.Forms;
using Microsoft.Build.Framework;
using PerformanceDude.MSBuildProfiler;

namespace MSBuildProfiler
{
    public class MSBuildProfileLogger : ILogger
    {
        #region ILogger Members

        public void Initialize(IEventSource eventSource)
        {
            var profiler = new PerformanceDude.MSBuildProfiler.MSBuildProfiler(eventSource);
            profiler.ProfilerFinished += OnProfilerFinished;
        }


        private static void OnProfilerFinished(Build build)
        {
            var t = new Thread(
                delegate()
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new MSBuildProfilerForm(build));
                    });
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }

        private string _parameters;

        public string Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }

        public void Shutdown()
        {
        }

        private LoggerVerbosity _verbosity;

        public LoggerVerbosity Verbosity
        {
            get { return _verbosity; }
            set { _verbosity = value; }
        }

        #endregion
    }
}